<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const obj = {
        firstName: "lao",
        lastName: "wang",
      };

      //
      Object.defineProperty(obj, "fullName", {
        get() {
          console.log(
            "fullName这个存取器getter函数被调用,返回值就是这个属性的值"
          );
          return this.firstName + " " + this.lastName;
        },
        set(value) {
          console.log(
            "fullName这个存取器setter函数被调用,接受的参数就是新设置的值"
          );
          console.log(value, "value");
          const [firstName, lastName] = value.split(" ");
          this.firstName = firstName;
          this.lastName = lastName;
        },
      });
      obj.fullName = "xiao huang";
      console.log(obj.fullName);
    </script>
  </body>
</html>
